<!doctype html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
		<meta http-equiv="content-script-type" content="text/javascript">
		<meta http-equiv="content-style-type" content="text/css">
		<meta name="author" content="Heidi Rakels">
		<meta name="description" content="Sanaware Java Docking - Developer guide - Dragging">
		<link rel="stylesheet" type="text/css" href="../style.css">
		<title>How to Use Dragging</title>
	</head>
<body>

<div class="nextprev">
<nobr><a href="codec.html">&laquo; prev</a></nobr>
<nobr><a href="componentfactory.html">next &raquo;</a></nobr>
</div>

<span class="item"><a href="../main/index.html">Java Docking Home</a></span>&gt;
<span class="item"><a href="index.html">Developer Guide</a></span>&gt;
<span class="selected item">How to Use Dragging</span>

<h2>
How to Use Dragging
</h2>

<a name="DraggerFactory"><!-- --></a>
<h3>
:: Dragging dockables ::
</h3>
<p>
A <a href="../javadoc/com/javadocking/drag/DraggerFactory.html" target="_blank">DraggerFactory</a> 
creates the draggers for dragging the dockables of your application.
You have to give your dragger factory to the <a href="../javadoc/com/javadocking/DockingManager.html" target="_blank">
DockingManager</a>.
</p>
<p>
By default the <a href="../javadoc/com/javadocking/drag/StaticDraggerFactory.html" target="_blank">
StaticDraggerFactory</a> is used. You can use a <a href="../javadoc/com/javadocking/drag/DynamicDraggerFactory.html" target="_blank">
DynamicDraggerFactory</a> like this:
<blockquote><pre>
		DockingManager.setDraggerFactory(new DynamicDraggerFactory());
</pre></blockquote>
</p>

<a name="StaticDragging"><!-- --></a>
<h3>
:: Static dragging ::
</h3>
<p>
By default this way of dragging is used.
When a <a href="../javadoc/com/javadocking/dockable/Dockable.html" target="_blank">
Dockable</a> is dragged, a representation of the dockable, 
is painted. This is done by a <a href="../javadoc/com/javadocking/drag/painter/DockableDragPainter.html" target="_blank">
DockableDragPainter</a>.
</p>
<p>
Usually this representation is a rectangle.
It shows where the dockable will be docked in a <a href="../javadoc/com/javadocking/dock/Dock.html" target="_blank">Dock</a>,
if the mouse would be released at the current mouse position.
This rectangle can be painted:
<ul>
<li>on the glass pane with a <a href="../javadoc/com/javadocking/drag/painter/SwDockableDragPainter.html" target="_blank">SwDockableDragPainter</a>,</li>
<li>on a window with a <a href="../javadoc/com/javadocking/drag/painter/WindowDockableDragPainter.html" target="_blank">WindowDockableDragPainter</a>,</li>
<li>or on a transparent window  with a <a href="../javadoc/com/javadocking/drag/painter/TransparentWindowDockableDragPainter.html" target="_blank">TransparentWindowDockableDragPainter</a>.</li>
</ul>
Some dockable drag painters:
<blockquote><pre>
		DockableDragPainter swDockableDragPainterWithoutLabel = new SwDockableDragPainter(new DefaultRectanglePainter(), false);
		DockableDragPainter swDockableDragPainterWithLabel = new SwDockableDragPainter(new RectangleDragComponentFactory(new DefaultRectanglePainter(), true), false);
		DockableDragPainter swDockableDragPainterWithoutLabelNoFloat = new SwDockableDragPainter(new DefaultRectanglePainter());
		DockableDragPainter swDockableDragPainterWithLabelNoFloat = new SwDockableDragPainter(new RectangleDragComponentFactory(new DefaultRectanglePainter(), true));
		DockableDragPainter labelDockableDragPainter = new LabelDockableDragPainter();
		DockableDragPainter imageDockableDragPainter = new ImageDockableDragPainter();
		DockableDragPainter windowDockableDragPainterWithoutLabel = new WindowDockableDragPainter(new DefaultRectanglePainter());
		DockableDragPainter windowDockableDragPainterWithLabel = new WindowDockableDragPainter(new DefaultRectanglePainter(), true);
		DockableDragPainter transparentWindowDockableDragPainterWithoutLabel = new TransparentWindowDockableDragPainter(new DefaultRectanglePainter());
		DockableDragPainter transparentWindowDockableDragPainterWithLabel = new TransparentWindowDockableDragPainter(new DefaultRectanglePainter(), true);
</pre></blockquote>
</p>
<p>
Different drag painters can be combined with the <a href="../javadoc/com/javadocking/drag/painter/CompositeDockableDragPainter.html" target="_blank">CompositeDockableDragPainter</a>:
<blockquote><pre>
			// Create the dockable drag painter and dragger factory.
			CompositeDockableDragPainter compositeDockableDragPainter = new CompositeDockableDragPainter();
			compositeDockableDragPainter.addPainter(basicDockableDragPainter);
			if (additionalDockableDragPainter != null)
			{
				compositeDockableDragPainter.addPainter(additionalDockableDragPainter);
			}
			DraggerFactory draggerFactory 	= new StaticDraggerFactory(compositeDockableDragPainter);
</pre></blockquote>
</p>
<p>
A rectangle to represent the dockable is painted with a 
<a href="../javadoc/com/javadocking/drag/painter/RectanglePainter.html" target="_blank">
RectanglePainter</a>. By default a 
<a href="../javadoc/com/javadocking/drag/painter/DefaultRectanglePainter.html" target="_blank">
DefaultRectanglePainter</a> is used.
You can change the layout of this drag rectangle by changing the
properties of this painter:
<blockquote><pre>
		// The drag rectangles have to be rubberbands.
		float[] pattern = {1.0f, 1.0f};
		Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, pattern, 0.0f);
		DefaultRectanglePainter borderPainter = new DefaultRectanglePainter();
		borderPainter.setStroke(stroke);
		borderPainter.setBorderColor(Color.black);
		borderPainter.setBorderCount(4);
		borderPainter.setBorderShift(1);
		borderPainter.setFillColor(null);
		borderPainter.setArcHeight(0);
		borderPainter.setArcWidth(0);
		SwDockableDragPainter dockableDragPainter = new SwDockableDragPainter(borderPainter);
		StaticDraggerFactory draggerFactory = new StaticDraggerFactory(dockableDragPainter);
		DockingManager.setDraggerFactory(draggerFactory);
</pre></blockquote>
</p>
<a name="DynamicDragging"><!-- --></a>
<h3>
:: Dynamic dragging ::
</h3>
<p>
When a dockable is dragged, and the mouse is above a dock where the dockable can be docked,
then the dockable is immediately docked in that dock, but the dragging can still be continued.
</p>
<p>
You can use dynamic dragging like this:
<blockquote><pre>
		DockingManager.setDraggerFactory(new DynamicDraggerFactory());
</pre></blockquote>
IMPORTANT: Sometimes dynamic dragging can be confusing for the users of your application,
especially when a dockable has a lot of possibilities to dock itself.
</p>

<a name="DraggingCursors"><!-- --></a>
<h3>
:: Dragging cursors ::
</h3>
<p>
By default the docking library uses the folowing cursors:
<ul>
	<li>When a dockable can be docked in a dock: java.awt.dnd.DragSource.DefaultMoveDrop.</li>
	<li>When a dockable cannot be docked in a dock: java.awt.dnd.DragSource.DefaultMoveNoDrop.</li>
</ul>
You can change these cursors like this:
<blockquote><pre>
		DockingManager.setCanDockCursor(myDockCursor);
		DockingManager.setCanNotDockCursor(myCanNotDockCursor);
</pre></blockquote>
</p>

<hr>

<br/>
The source code of the samples can be found in:
<br/><br/>
<table>
<tr>
	<td><a href="code/DynamicDragging.java.html">DynamicDragging</a></td><td>Shows dynamic dragging of dockables.</td>
</tr>
<tr>
	<td><a href="code/DragRectangle.java.html">DragRectangle</a></td><td>Shows other drag rectangles.</td>
</tr>
<tr>
	<td><a href="code/DragPainter.java.html">DragPainter</a></td><td>Shows combinations of dockable drag painters.</td>
</tr>
</table>

<br/>
<hr>
<br/>

<div class="nextprevbottom">
<nobr><a href="codec.html">&laquo; prev</a></nobr>
<nobr><a href="componentfactory.html">next &raquo;</a></nobr>
</div>

</body>

</html>